#include <bits/stdc++.h>
using namespace std;
int a[100005];
int d[100005];
int v[100005];
int p[100005];
int w[100005];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    while(t--){
        int n,m,L,V;
        cin>>n>>m>>L>>V;
        for(int i=1; i<=n; i++) cin>>d[i]>>v[i]>>a[i];
        for(int i=1; i<=m; i++) cin>>p[i];
        int cnt=0;
        for(int i=1; i<=n; i++){
            if(v[i]>=V&&a[i]>0){
                w[i]=1;
                cnt++;
                break;
            }
            double k=v[i];
            for(int j=1; j<=m; j++){
                int t=1;
                k=0.5*a[i]*1.0;
                while(k<p[j]){
                    t++,k=0.5*a[i]*(t*t*1.0);
                    if(k==0) break;
                }
                double sd=sqrt(v[i]*v[i]*1.0+2.0*a[i]*k);
                if(sd<=V) continue;
                w[i]=j+(k!=p[i]);
                break;
            }
            if(w[i]>0&&w[i]<=m) cnt++;
        }
        cout<<cnt<<" "<<cnt<<"\n";
    }
    return 0;
}
